package example.telosys.persistence.sqlscript ;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

import org.telosys.common.TelosysException;
import org.telosys.persistence.database.DatabaseManager;
import org.telosys.persistence.sql.SqlScriptExecutor;

import test.telosys.persistence.TestCommons;

public class SqlScript {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws TelosysException
	{
		TestCommons.init();
		
		Connection connection = DatabaseManager.getConnection();
		
//		String sqlFile1 = TestCommons.getFullFileName("sql/void.sql");
//		String sqlFile2 = TestCommons.getFullFileName("sql/restaurants.sql");
		
		String sqlFile1 = SqlScriptUtil.getSqlScriptFileName("void.sql");
		String sqlFile2 = SqlScriptUtil.getSqlScriptFileName("restaurants.sql");
		
		SqlScriptExecutor r = new SqlScriptExecutor(connection, SqlScriptExecutor.AUTOCOMMIT );
		
		try {
			r.executeScript(sqlFile1);
			r.executeScript(sqlFile2);
			r.executeScript(sqlFile1);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		finally {
			
			try {
				connection.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}

}
